{extend name="layout:base" /}
{block name="main_content"}
  <div class="page-content">
    <!--主题-->
    <?php if(!empty($current_page)): ?>
      <div class="page-header">
        <h1>
          您当前操作
          <small>
            <i class="ace-icon fa fa-angle-double-right"></i>
            {$current_page.title|default=''}
          </small>
        </h1>
      </div>
    <?php endif; ?>
    <div class="row">
      <div class="col-xs-12">
        <form class="form-horizontal adminform" id="model-form" method="post" action="">
          <div class="form-group">
            <label class="col-sm-2 control-label no-padding-right" for="form-field-1">
              上级菜单：
            </label>
            <div class="col-sm-10">
              <select name="parent_id"  class="col-sm-5" required>
                <option value="0">顶级菜单</option>
                {volist name="list" id="vo"}
                  <option value="{$vo.id}"  <?php if(isset($rule["parent_id"]) && $rule["parent_id"]==$vo["id"]){echo('selected="selected"');} ?>>{$vo.shown_title}</option>
                {/volist}
              </select>
            </div>
          </div>
          <div class="space-4"></div>

          <div class="form-group">
            <label class="col-sm-2 control-label no-padding-right" for="form-field-1"> 
              菜单名称：<span class="red">*</span>
            </label>
            <div class="col-sm-10">
              <input type="text" name="title" placeholder="请输入菜单名称" class="col-xs-10 col-sm-5" value="{$rule.title|default=''}" required/>
              
            </div>
          </div>
          <div class="space-4"></div>

          <div class="form-group">
            <label class="col-sm-2 control-label no-padding-right" for="form-field-1">
              页面链接：
            </label>
            <div class="col-sm-10">
              <input type="text" name="name" placeholder="请输入页面链接" class="col-xs-10 col-sm-5" value="{$rule.name|default=''}"/>
            </div>
          </div>
          <div class="space-4"></div>

          <div class="form-group">
            <label class="col-sm-2 control-label no-padding-right" for="form-field-1"> ICON图标：  </label>
            <div class="col-sm-10">
              <input type="text" name="icon" placeholder="例:menu-icon fa fa-tachometer" value="{$rule.icon|default=''}" class="col-xs-10 col-sm-5"/>
            </div>
          </div>
          <div class="space-4"></div>

          <div class="form-group">
            <label class="col-sm-2 control-label no-padding-right" for="form-field-1"> 显示状态：  </label>
            <div class="col-sm-10" style="padding-top:5px;">
              <input name="status" value="1" class="ace ace-switch ace-switch-4 btn-flat" type="checkbox" <?php if(isset($rule["status"]) && intval($rule["status"])){echo('checked="checked"');} ?> />
              <span class="lbl"></span>
            </div>
          </div>
          <div class="space-4"></div>

          <div class="form-group">
            <label class="col-sm-2 control-label no-padding-right" for="form-field-1"> 排序编号：  </label>
            <div class="col-sm-10">
              <input type="text" name="sort" maxlength="4" placeholder="编号越小越靠前" value="{$rule.sort|default='0'}" class="col-xs-10 col-sm-5"/>
            </div>
          </div>
          <div class="space-4"></div>

          <div class="clearfix form-actions">
            <div class="col-md-offset-3 col-md-9">
              <?php if(isset($rule['id'])): ?>
                <input type="hidden" name="id" value="{$rule.id}">
              <?php endif; ?>
              <button class="btn btn-info" type="submit">
                <i class="ace-icon fa fa-check bigger-110"></i>
                保存
              </button>

              &nbsp; &nbsp; &nbsp;
              <button class="btn" type="reset">
                <i class="ace-icon fa fa-undo bigger-110"></i>
                重置
              </button>
            </div>
          </div>
        </form>
      </div>
    </div>
  </div>
{/block}
{block name="page_js"}
  <script src="{$site_root}/static/plugins/jquery-validate/jquery.validate.min.js"></script>
  <script type="text/javascript">
    $("form#model-form").validate({
      rules:{
        "title":{
          required: true,
          minlength: 1,
          maxlength: 30
        }, "name":{
          // required: true,
          // minlength: 1,
          maxlength: 30
        }, "icon":{
          maxlength: 50
        }, "sort":{
          min: 0,
          max: 9999
        }
      },
      messages:{
        "title":{
          required: "菜单名称不能为空",
          minlength: "菜单名称不能少于1个字符",
          maxlength: "菜单名称不能超过30个字符"
        }, "name":{
          // required: "页面链接不能为空",
          // minlength: "页面链接不能少于1个字符",
          maxlength: "页面链接不能超过30个字符"
        }, "icon":{
          maxlength: "ICON图标不能超过30个字符"
        }, "sort":{
          min: "排序编号不能小于0",
          max: "排序编号不能大于9999"
        }
      },
      errorClass: "help-inline input-error",
      errorElement: "span",
      highlight:function(element, errorClass, validClass) {
        $(element).parents('.form-group').addClass('has-error');
      },
      unhighlight: function(element, errorClass, validClass) {
        $(element).parents('.form-group').removeClass('has-error');
        // $(element).parents('.form-group').addClass('success');
      },
      submitHandler: function(form){
        var $form = $(form);
        $.ajax({
          url: $form.attr("action"),
          type: $form.attr("method"),
          dataType: "JSON",
          data: $form.serialize(),
          success: function(data){
            if(data.code){
              location.href = data["url"];
            }else{
              alert(data["msg"]);
            }
          }, error: function () {
            alert("数据执行错误！");
          }
        });
      }
    });
  </script>
{/block}